package com.deyuanyun.pic.wf.support;

import com.deyuanyun.pic.common.spring.SpringAppliction;
import com.deyuanyun.pic.common.util.ObjectUtil;
import com.deyuanyun.pic.wf.domain.ProcessDefinition;
import com.deyuanyun.pic.wf.domain.ProcessInstance;
import com.deyuanyun.pic.wf.domain.ProcessInstanceExample;
import com.deyuanyun.pic.wf.service.ProcessDefinitionService;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 流程定义公共类
 *
 * @author huanglw
 * @date
 *
 * History: [修改人][时间][修改描述]
 */
public class ProcessDefinitionUtil {

    private static Map<String, String> processDefinitionMap = null;

    private List<ProcessDefinition> getProcessDefinition() {
        ProcessDefinitionService processDefinitionService = SpringAppliction.getBean(ProcessDefinitionService.class);
        return processDefinitionService.queryProcessDefinitionPbfAll();
    }

    /**
     * 根据id，得到流程定义的名称
     *
     * @param id
     * @return
     */
    public static String getProcessDefinitionName(String id) {
        if (ObjectUtil.isEmptyAll(processDefinitionMap)) {
            processDefinitionMap = new HashMap<String, String>();
            List<ProcessDefinition> processDefinitionList = new ProcessDefinitionUtil().getProcessDefinition();
            for (ProcessDefinition processDefinition : processDefinitionList){
                processDefinitionMap.put(processDefinition.getId(), processDefinition.getName());
            }
        }
        return processDefinitionMap.get(id);
    }
}